package com.buss.core.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.MapKeyType;
import org.hibernate.annotations.Type;

import com.buss.core.dic.MenuType;
import com.buss.core.utils.SimpleEnumSerializer;

/**
 * 系统模型管理，主要管理系统所有功能模块
 * @author gykl
 *
 */
@Entity
@Table(name="core_sysmenu")
@TableGenerator(name="sysmenu_pk_sequence",initialValue=1,allocationSize=1,pkColumnName="seq_col",
		pkColumnValue="sysmenu_seq",valueColumnName="seq_val",table="core_pk_sequence")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JsonIgnoreProperties(value="hibernateLazyInitializer")
public class Sysmenu implements Serializable{

	private static final long serialVersionUID = -7587312371933801014L;

	public Sysmenu(){}
	
	public Sysmenu(Long id,String code){
		super();
		this.id = id;
		this.code = code;
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator="sysmenu_pk_sequence")
	private Long id;
	
	/**菜单功能编码*/
	@Column(nullable = false,length = 20)
	private String code;
	
	/**菜单名称*/
	@Column(nullable = false,length = 100)
	private String name;
	
	/**菜单图片*/
	@Column(length = 100)
	private String iconPath;
	
	/**菜单对应的URL*/
	@Column(length = 100,name="url")
	private String menuUrl;
	
	/**是否停用*/
	private Boolean disabled;
	
	/**父级菜单ID*/
	@Column(nullable=false)
	private Long parentId;
	
	/**子菜单数量*/
	@Column(nullable=false)
	private Long nodeNum;
	
	/**排序序号*/
	private Long seqNum;
	
	/**是否有子节点*/
	@Transient
	private boolean hasNode;
	
	/**节点层级*/
	@Transient
	private Integer childLevel;
	
	/**是否展开节点*/
	@Transient
	private boolean open;
	
	/**菜单类型*/
	@Enumerated(EnumType.STRING)	
	private MenuType menuType;
	
	/**菜单对应角色信息列表*/
	
	@ManyToMany(mappedBy="sysmenus",fetch=FetchType.LAZY,cascade=CascadeType.REFRESH,targetEntity=Role.class)
	private List<Role> roles;
	
	/**子菜单列表信息*/
	@Transient
	private List<Sysmenu> nodes;
	
	/**复选框是否被选中*/
	@Transient
	private Boolean checked;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIconPath() {
		return iconPath;
	}

	public void setIconPath(String iconPath) {
		this.iconPath = iconPath;
	}


	public String getMenuUrl() {
		return menuUrl;
	}

	public void setMenuUrl(String menuUrl) {
		this.menuUrl = menuUrl;
	}

	

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public Long getNodeNum() {
		return nodeNum;
	}

	public void setNodeNum(Long nodeNum) {
		this.nodeNum = nodeNum;
	}

	public Long getSeqNum() {
		return seqNum;
	}

	public void setSeqNum(Long seqNum) {
		this.seqNum = seqNum;
	}
	
	public boolean isHasNode() {
		return hasNode;
	}

	public void setHasNode(boolean hasNode) {
		this.hasNode = hasNode;
	}

	public Integer getChildLevel() {
		return childLevel;
	}

	public void setChildLevel(Integer childLevel) {
		this.childLevel = childLevel;
	}


	public Boolean getDisabled() {
		return disabled;
	}

	public void setDisabled(Boolean disabled) {
		this.disabled = disabled;
	}

	public boolean isOpen() {
		return this.open;
	}

	public void setOpen(boolean open) {
		this.open = open;
	}

	@JsonSerialize(using=SimpleEnumSerializer.class)
	public MenuType getMenuType() {
		return menuType;
	}

	public void setMenuType(MenuType menuType) {
		this.menuType = menuType;
	}

	public List<Sysmenu> getNodes() {
		return nodes;
	}

	public void setNodes(List<Sysmenu> nodes) {
		this.nodes = nodes;
	}
	@JsonDeserialize
	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	public Boolean getChecked() {
		return checked;
	}

	public void setChecked(Boolean checked) {
		this.checked = checked;
	}
	
}
